package com.boge.modules.house.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.boge.modules.house.entity.TReservationEntity;
import com.boge.modules.house.service.TReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boge.modules.house.entity.TLeaseEntity;
import com.boge.modules.house.service.TLeaseService;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.R;



/**
 * 
 *
 * @author boge
 * @email dengpbs@163.com
 * @date 2024-12-04 22:12:55
 */
@RestController
@RequestMapping("house/tlease")
public class TLeaseController {
    @Autowired
    private TLeaseService tLeaseService;


    @Autowired
    private TReservationService reservationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("house:tlease:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tLeaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("house:tlease:info")
    public R info(@PathVariable("id") Integer id){
		TLeaseEntity tLease = tLeaseService.getById(id);

        return R.ok().put("tLease", tLease);
    }

    /**
     * 保存 status 1 2
     */
    @RequestMapping("/save")
    //@RequiresPermissions("house:tlease:save")
    public R save(@RequestBody TLeaseEntity tLease){
        // 如果有传递预约ID 需要根据预约id 获取 房屋和预约人信息
        TReservationEntity reservationEntity = reservationService.getById(tLease.getYyId());
        if(reservationEntity != null){
            tLease.setHouseId(reservationEntity.getHouseId());
            tLease.setUserId(reservationEntity.getUserId());
        }
        tLeaseService.save(tLease);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("house:tlease:update")
    public R update(@RequestBody TLeaseEntity tLease){
		tLeaseService.updateById(tLease);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("house:tlease:delete")
    public R delete(@RequestBody Integer[] ids){
		tLeaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
